<?php

namespace app\common\model;

/**
 * [News  资讯表]
 * @author [C。]
 * @return html
 */
class News extends Base
{
    protected $name = 'news';
    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getlist($map,$from = 0, $size = 5,$field,$order = ['n.id' => 'desc'])
    {
        $join = [
            ['app_cate c','n.cateid = c.id'],
        ];

        $result =  $this->field($field)
            ->alias('n')
            ->join($join)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }

    /**
     * 搜索获取寺院列表总数
     * @param array $param
     */
    public function getCount($map) {
        $join = [
            ['app_cate c','n.cateid = c.id'],
        ];
        $result =  $this->alias('n')
            ->join($join)
            ->where($map)
            ->count();

        return $result;
    }
    /**
     * 获取单条
     * @param array $param
     */
    public function getOne($map,$fields='*') {
        $order = ['id' => 'desc'];
        $result = $this->field($fields)->where($map)->order($order)->find();
        return $result;
    }
    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getlists($map,$from = 0, $size = 5,$fields='id,title,cover,comid,addtime,read_num,content,istop,recommend,from,jread_num')
    {
        $order = ['istop' => 'desc','recommend'=>'desc','id' => 'desc'];
        $result =  $this->field($fields)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
    /**
     * 搜索获取寺院列表总数
     * @param array $param
     */
    public function getCounts($map) {
        $result =  $this->where($map)->count();
        return $result;
    }
    /**
     * 根据搜索条件获取寺院列表信息
     */
    public function getHotlist($map,$from = 0, $size = 5,$fields='id,title,cover,addtime,read_num,content,istop,recommend')
    {
        $order = ['read_num' => 'desc'];
        $result =  $this->field($fields)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
}